<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>匿名提问箱</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            text-align: center;
            background-color: #ffffff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            max-width: 400px;
            width: 100%;
        }
        h1 {
            color: #333333;
            margin-bottom: 20px;
        }
        textarea {
            width: 100%;
            height: 100px;
            padding: 10px;
            border: 1px solid #cccccc;
            border-radius: 5px;
            font-size: 16px;
            margin-bottom: 20px;
            resize: none;
        }
        button {
            background-color: #007bff;
            color: #ffffff;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        .decorative-image {
            margin-top: 20px;
        }
        .decorative-image img {
            width: 100px;
            height: auto;
        }
        .response {
            margin-top: 20px;
            color: #333333;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>向我发起提问吧！</h1>
        <textarea placeholder="在这里输入你的问题..."></textarea>
        <button onclick="submitQuestion()">提交问题</button>
        <div class="response" id="response"></div>
    </div>

    <script>
        async function submitQuestion() {
            const question = document.querySelector('textarea').value;
            const responseDiv = document.getElementById('response');

            if (question.trim() === '') {
                alert('请输入问题！');
                return;
            }

            try {
                // 发送AJAX请求
                const response = await fetch('http://127.0.0.1:8080/ask?asker=20230100045&question_no=6789&content=' + question, {
                    method: 'GET',
                    //headers: {
                    //    'Content-Type': 'application/json',
                    //},
                    //body: JSON.stringify({ question: question }),
                });

                if (!response.ok) {
                    throw new Error('网络响应异常');
                }

                const data = await response.json(); // 解析服务器返回的JSON数据
                responseDiv.textContent = `服务器返回：${data.message}`; // 显示服务器返回的数据
            } catch (error) {
                responseDiv.textContent = '提交失败，请稍后重试。';
                console.error('提交失败：', error);
            } finally {
                document.querySelector('textarea').value = ''; // 清空输入框
            }
        }
    </script>
</body>
</html>